#!/usr/bin/env sh

#$1,dir,all file in this dir would be calculate shasum
cal_shasum()
{
    cal_cur_dir=`pwd`
    cal_shasum_dir=$1
    if [ -d $cal_shasum_dir ]; then
        cd $cal_shasum_dir
        for file_name in $(ls)
        do
            if [ -f $file_name ] ; then
                file_size=$(ls -lh $file_name | awk '{printf $5}')
                file_sha=$(shasum $file_name | cut -d ' ' -f 1)
                file_path=$cal_shasum_dir/$file_name
                printf "%5s %s %s\n" "$file_size" "$file_sha" "$file_path"
            elif [ -d $file_name ]; then
                cal_shasum $file_name
            fi
        done
    fi
    cd $cal_shasum_dir
}

dir1=$HOME/Downloads

cal_shasum $dir1
